package cn.langpy.dblistener.core;

import cn.langpy.dblistener.core.model.OperateType;
import cn.langpy.dblistener.core.model.transform.EventRow;

/**
 * zhangchang
 * sql解析接口
 */

public interface SqlParser {


    default String getSql(String dataBase, String table, EventRow eventRow) {
        String sql = "";
        if (OperateType.INSERT==eventRow.getOperate()) {
            sql = toInsertSql(dataBase, table, eventRow);
        } else if (OperateType.DELETE==eventRow.getOperate()) {
            sql = toDeleteSql(dataBase, table, eventRow);
        } else if (OperateType.UPDATE==eventRow.getOperate()) {
            sql = toUpdateSql(dataBase, table, eventRow);
        } else if (OperateType.READ==eventRow.getOperate()) {
            sql = toInsertSql(dataBase, table, eventRow);
        }
        return sql;
    }

    String toInsertSql(String dataBase, String tableName, EventRow rowData);

    String toDeleteSql(String dataBase, String tableName, EventRow rowData);

    String toUpdateSql(String dataBase, String tableName, EventRow rowData);
}
